﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq.Expressions;
using System.Text;

namespace Core
{
    /// <summary>
    /// 创建基础常用接口
    /// </summary>
    public interface IBaseService:IDependency
    {
        /// <summary>
        /// 添加接口
        /// </summary>
        /// <typeparam name="T">传入泛型类</typeparam>
        /// <param name="entity">参数名</param>
        /// <returns></returns>
        int Insert<T>(T entity) where T : class;
        /// <summary>
        /// 修改接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Update<T>(T entity) where T : class;

        /// <summary>
        /// 删除接口 依据实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Delete<T>(T entity) where T : class;
        /// <summary>
        /// 删除接口 依据条件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Delete<T>(Expression<Func<T, bool>> where) where T : class;
        /// <summary>
        /// 根据ID判断数据是否存在
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ID">数据主键</param>
        /// <returns></returns>
        bool Exists<T>(object ID) where T : class;
        /// <summary>
        /// 保存单个数据信息，可添加可修改
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="ID">数据主键</param>
        /// <returns></returns>
        int Save<T>(T entity, object ID) where T : class;
        /// <summary>
        /// 保存数据集合，可添加可修改
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dataList"></param>
        /// <returns></returns>
        int Save<T>(List<T> dataList) where T : class;
        /// <summary>
        /// 获取单条数据信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ID">数据主键</param>
        /// <returns></returns>
        T GetModel<T>(object ID) where T : class;
        /// <summary>
        /// 获取单条数据信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ID">数据主键</param>
        /// <returns></returns>
        T GetModel<T>(Expression<Func<T, bool>> where, Action<IOrderable<T>> order = null) where T : class;
        /// <summary>
        /// 获取数据集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="where">条件</param>
        /// <param name="order">排序</param>
        /// <returns></returns>
        List<T> GetList<T>(Expression<Func<T, bool>> where, Action<IOrderable<T>> order = null) where T : class;
        /// <summary>
        /// 重构获取集合方法 复杂sql语句
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="table">表名</param>
        /// <param name="strWhere">where条件  sql语句</param>
        /// <returns>返回当前类集合</returns>
        //List<T> GetList<T>(string table, string strWhere = "") where T : class;
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="PageIndex">当前页</param>
        /// <param name="PageSize">每页条数</param>
        /// <param name="count">返回总行数</param>
        /// <param name="where"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        List<T> GetList<T>(int PageIndex, int PageSize, ref int count, Expression<Func<T, bool>> where = null, Action<IOrderable<T>> order = null) where T : class;
        /// <summary>
        /// 根据条件获取数据总数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="where">条件</param>
        /// <returns></returns>
        int GetCount<T>(Expression<Func<T, bool>> where) where T : class;
        /// <summary>
        /// 执行sql查询，可接受存储过程
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="parmrters"></param>
        /// <returns></returns>
        DataTable GetSql(string sql, SqlParameter[] parmrters, CommandType type);


    }
}
